﻿<UserControl x:Class="theeg.DependencyAnalysis.CommonAddin.Views.MetricsGrid"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:serialization="clr-namespace:DependencyAnalysis.Serialization;assembly=DependencyAnalysis"
             xmlns:commonAddin="clr-namespace:theeg.DependencyAnalysis.CommonAddin"
             xmlns:behaviors="clr-namespace:theeg.DependencyAnalysis.CommonAddin.Behaviors"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/CommonStyles.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <SolidColorBrush x:Key="GridLineBrush" Color="CornflowerBlue"></SolidColorBrush>
            <ControlTemplate x:Key="ExpanderWithoutButton" TargetType="{x:Type Expander}">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="0"
                    Background="{TemplateBinding Background}"
                    SnapsToDevicePixels="true">
                    <DockPanel>
                        <ContentPresenter Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                            DockPanel.Dock="Top"
                            Margin="1"
                            Focusable="false" />
                        <ContentPresenter x:Name="ExpandSite"
                            Visibility="Collapsed"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}"
                            Focusable="false" />
                    </DockPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsExpanded" Value="true">
                        <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style TargetType="TextBlock" x:Key="MetricsTextBlock">
                <Setter Property="Margin" Value="3,2,3,2"></Setter>
                <Setter Property="Width" Value="60"></Setter>
                <Setter Property="TextAlignment" Value="Right"></Setter>
                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                <Setter Property="Foreground" Value="White"></Setter>
            </Style>

            <Style x:Key="ExpandCollapseToggleStyle"
           TargetType="{x:Type ToggleButton}">
                <Setter Property="Focusable"
              Value="False"/>
                <Setter Property="Width"
              Value="40"/>
                <Setter Property="Height"
              Value="20"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                            <Border Width="40"
                    Height="20"
                    Background="Transparent">
                                <Border Width="35"
                      Height="18"
                      BorderThickness="1"
                      BorderBrush="White"
                                        Background="#0625334B"
                      CornerRadius="1"
                      SnapsToDevicePixels="true">
                                    <TextBlock x:Name="ExpandPath" Margin="0,2,0,0" Foreground="White" Text="+" FontWeight="Regular" HorizontalAlignment="Center"
                                           VerticalAlignment="Center" FontFamily="Segoe UI, Arial" FontSize="18"/>
                                </Border>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked"
                       Value="True">
                                    <Setter Property="Text"
                        TargetName="ExpandPath"
                        Value="-"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="HeaderButtonStyle" TargetType="Button">
                <Setter Property="FontWeight" Value="Bold"></Setter>
                <Setter Property="Command" Value="{x:Static commonAddin:AddinWindow.SortMetricsCommand}"></Setter>
                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                <Setter Property="Background" Value="LightBlue"></Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentControl Content="{TemplateBinding Content}" HorizontalAlignment="Center" Margin="3"></ContentControl>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}" HorizontalAlignment="Right"></Rectangle>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#FF9696B6"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <DataTemplate x:Key="MemberHeaderElement">
                <Border Background="LightBlue" BorderThickness="0">
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="404">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>Name</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Name
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Cyclomatic complexity">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>CyclomaticComplexity</sys:String>
                                </x:Array>
                            </Button.CommandParameter> CC
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of instructions">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>NumberOfInstructions</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Ins
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Nesting depth">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>NestingDepth</sys:String>
                                </x:Array>
                            </Button.CommandParameter> ND
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of parameters">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>NumberOfParameters</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Par
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of variables">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>NumberOfVariables</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Var
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Afferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>AfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ca
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Efferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsMember</sys:String>
                                    <sys:String>EfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ce
                        </Button>
                    </StackPanel>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="TypeHeaderElement">
                <Border Background="LightBlue" BorderThickness="0">
                    <StackPanel Orientation="Horizontal">
                        <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" Visibility="Hidden"></ToggleButton>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="393">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>Name</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Name
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Lack of cohesion Henderson Sellers">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>LackOfCohesion</sys:String>
                                </x:Array>
                            </Button.CommandParameter> LCOMHS
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of instructions">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfInstructions</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Ins
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of fields">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfFields</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #F
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of interfaces">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfInterfaces</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #IF
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of methods">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfMethods</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #M
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of children">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfChildren</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Ch
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of overridden methods">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>NumberOfOverriddenMethods</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Mo
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Depth of inheritance">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>DepthOfInheritance</sys:String>
                                </x:Array>
                            </Button.CommandParameter> DIT
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Cyclomatic complexity">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>CyclomaticComplexity</sys:String>
                                </x:Array>
                            </Button.CommandParameter> CC
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Specialization index">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>SpecializationIndex</sys:String>
                                </x:Array>
                            </Button.CommandParameter> SIX
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Association between classes">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>AssociationBetweenClasses</sys:String>
                                </x:Array>
                            </Button.CommandParameter> ABC
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Afferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>AfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ca
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Efferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsType</sys:String>
                                    <sys:String>EfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ce
                        </Button>
                    </StackPanel>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="SubmoduleHeaderElement" >
                <Border Background="LightBlue" BorderThickness="0">
                    <StackPanel Orientation="Horizontal">
                        <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" Visibility="Hidden"></ToggleButton>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="401">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>Name</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Name
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Distance from main sequence">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>DistanceFromMainSequence</sys:String>
                                </x:Array>
                            </Button.CommandParameter> D
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Instability">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>Instability</sys:String>
                                </x:Array>
                            </Button.CommandParameter> I
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Abstractness">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>Abstractness</sys:String>
                                </x:Array>
                            </Button.CommandParameter> A
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Relational cohesion">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>RelationalCohesion</sys:String>
                                </x:Array>
                            </Button.CommandParameter> RC
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Afferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>AfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ca
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Efferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>EfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ce
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of types">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsSubmodule</sys:String>
                                    <sys:String>NumberOfTypes</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Types
                        </Button>
                    </StackPanel>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="ModuleHeaderElement">
                <Border Background="LightBlue">
                    <StackPanel Orientation="Horizontal">
                        <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" Visibility="Hidden"></ToggleButton>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="409">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>Name</sys:String>
                                </x:Array>
                            </Button.CommandParameter>
                            Name
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Distance from main sequence">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>DistanceFromMainSequence</sys:String>
                                </x:Array>
                            </Button.CommandParameter> D
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Instability">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>Instability</sys:String>
                                </x:Array>
                            </Button.CommandParameter> I
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Abstractness">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>Abstractness</sys:String>
                                </x:Array>
                            </Button.CommandParameter> A
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Relational cohesion">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>RelationalCohesion</sys:String>
                                </x:Array>
                            </Button.CommandParameter> RC
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Afferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>AfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ca
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Efferent coupling">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>EfferentCoupling</sys:String>
                                </x:Array>
                            </Button.CommandParameter> Ce
                        </Button>
                        <Button Style="{StaticResource HeaderButtonStyle}" Width="67" ToolTip="Number of types">
                            <Button.CommandParameter>
                                <x:Array Type="{x:Type sys:String}">
                                    <sys:String>MetricsModule</sys:String>
                                    <sys:String>NumberOfTypes</sys:String>
                                </x:Array>
                            </Button.CommandParameter> #Types
                        </Button>
                    </StackPanel>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="MemberTemplate" DataType="serialization:DataContractExpandoObject">
                <StackPanel x:Name="content">
                    <StackPanel Orientation="Horizontal">
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <Image Source="../Resources/Method.png" Margin="2,0,0,0"></Image>
                        <Button DataContext="{Binding}" Content="{Binding Name}" Style="{StaticResource SelectButtonStyle}" Width="378"></Button>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding CyclomaticComplexity}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding NumberOfInstructions}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding NestingDepth}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding NumberOfParameters}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding NumberOfVariables}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding AfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                        <TextBlock Text="{Binding EfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                        <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                    </StackPanel>
                </StackPanel>
                <DataTemplate.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Transparent" 
                            TargetName="content"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#22FFFFFF" 
                            TargetName="content"></Setter>
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="TypeTemplate" DataType="serialization:DataContractExpandoObject">
                <Expander Template="{StaticResource ExpanderWithoutButton}" x:Name="expander" IsExpanded="{Binding IsExpanded}">
                    <Expander.Tag>
                        <CollectionViewSource x:Name="viewSource" Source="{Binding Members}" behaviors:ViewSourceGroupBehavior.GroupName="MetricsMember" >
                            <CollectionViewSource.SortDescriptions>
                                <scm:SortDescription PropertyName="Name"/>
                            </CollectionViewSource.SortDescriptions>
                        </CollectionViewSource>
                    </Expander.Tag>
                    <Expander.Header>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding ElementName=expander, Path=IsExpanded, Mode=TwoWay}"></ToggleButton>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <Image Source="../Resources/Class.png" Margin="2,0,0,0"></Image>
                                <Button DataContext="{Binding}" Content="{Binding Name}" Style="{StaticResource SelectButtonStyle}" Width="366"></Button>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding LackOfCohesion, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfInstructions}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfFields}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfInterfaces}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfMethods}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfChildren}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfOverriddenMethods}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding DepthOfInheritance}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding CyclomaticComplexity}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding SpecializationIndex, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding AssociationBetweenClasses, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding AfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding EfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <ItemsControl ItemsSource="{Binding Path=.,ElementName=viewSource}" ItemTemplate="{StaticResource MemberTemplate}" Margin="8,0,0,0"
                              AlternationCount="2">
                        <ItemsControl.Template>
                            <ControlTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="2"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <ContentPresenter ContentTemplate="{StaticResource MemberHeaderElement}" Content=""></ContentPresenter>
                                    <ItemsPresenter Grid.Row="1"></ItemsPresenter>
                                    <Rectangle VerticalAlignment="Stretch" Fill="{StaticResource GridLineBrush}" Grid.Row="2"></Rectangle>
                                </Grid>
                            </ControlTemplate>
                        </ItemsControl.Template>
                    </ItemsControl>
                </Expander>
                <DataTemplate.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Transparent" 
                            TargetName="expander"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#22FFFFFF" 
                            TargetName="expander"></Setter>
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="SubmoduleTemplate" DataType="serialization:DataContractExpandoObject">
                <Expander Template="{StaticResource ExpanderWithoutButton}" x:Name="expander" IsExpanded="{Binding IsExpanded}">
                    <Expander.Tag>
                        <CollectionViewSource x:Name="viewSource" Source="{Binding Types}" behaviors:ViewSourceGroupBehavior.GroupName="MetricsType" >
                            <CollectionViewSource.SortDescriptions>
                                <scm:SortDescription PropertyName="Name"/>
                            </CollectionViewSource.SortDescriptions>
                        </CollectionViewSource>
                    </Expander.Tag>
                    <Expander.Header>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding ElementName=expander, Path=IsExpanded, Mode=TwoWay}"></ToggleButton>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <Image Source="../Resources/Namespace.png" Margin="2,0,0,0"></Image>
                                <Button DataContext="{Binding}" Content="{Binding Name}" Style="{StaticResource SelectButtonStyle}" Width="374"></Button>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding DistanceFromMainSequence, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding Instability, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding Abstractness, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding RelationalCohesion, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding AfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding EfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfTypes}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <ItemsControl ItemsSource="{Binding Path=.,ElementName=viewSource}" ItemTemplate="{StaticResource TypeTemplate}" Margin="8,0,0,0"
                              AlternationCount="2">
                        <ItemsControl.Template>
                            <ControlTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="2"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <ContentPresenter ContentTemplate="{StaticResource TypeHeaderElement}" Content=""></ContentPresenter>
                                    <ItemsPresenter Grid.Row="1"></ItemsPresenter>
                                    <Rectangle VerticalAlignment="Stretch" Fill="{StaticResource GridLineBrush}" Grid.Row="2"></Rectangle>
                                </Grid>
                            </ControlTemplate>
                        </ItemsControl.Template>
                    </ItemsControl>
                </Expander>
                <DataTemplate.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Transparent" 
                            TargetName="expander"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#22FFFFFF" 
                            TargetName="expander"></Setter>
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="ModuleTemplate" DataType="serialization:DataContractExpandoObject">
                <Expander Template="{StaticResource ExpanderWithoutButton}" x:Name="expander" IsExpanded="{Binding IsExpanded}">
                    <Expander.Tag>
                        <CollectionViewSource x:Name="viewSource" Source="{Binding Submodules}" behaviors:ViewSourceGroupBehavior.GroupName="MetricsSubmodule" >
                            <CollectionViewSource.SortDescriptions>
                                <scm:SortDescription PropertyName="Name"/>
                            </CollectionViewSource.SortDescriptions>
                        </CollectionViewSource>
                    </Expander.Tag>
                    <Expander.Header>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding ElementName=expander, Path=IsExpanded, Mode=TwoWay}"></ToggleButton>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <Image Source="../Resources/Module.png" Margin="2,0,0,0"></Image>
                                <Button DataContext="{Binding}" Content="{Binding Name}" Style="{StaticResource SelectButtonStyle}" Width="382"></Button>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding DistanceFromMainSequence, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding Instability, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding Abstractness, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding RelationalCohesion, StringFormat={}{0:0.00}}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding AfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding EfferentCoupling}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                                <TextBlock Text="{Binding NumberOfTypes}" Style="{StaticResource MetricsTextBlock}"></TextBlock>
                                <Rectangle VerticalAlignment="Stretch" Width="1" Fill="{StaticResource GridLineBrush}"></Rectangle>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <ItemsControl ItemsSource="{Binding Path=.,ElementName=viewSource}" ItemTemplate="{StaticResource SubmoduleTemplate}" Margin="8,0,0,0"
                              AlternationCount="2">
                        <ItemsControl.Template>
                            <ControlTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="2"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <ContentPresenter x:Name="content" ContentTemplate="{StaticResource SubmoduleHeaderElement}" Content=""></ContentPresenter>
                                    <ItemsPresenter Grid.Row="1"></ItemsPresenter>
                                    <Rectangle Width="{Binding ElementName=content, Path=ActualWidth}" VerticalAlignment="Stretch" Fill="{StaticResource GridLineBrush}" Grid.Row="2"></Rectangle>
                                </Grid>
                            </ControlTemplate>
                        </ItemsControl.Template>
                    </ItemsControl>
                </Expander>
                <DataTemplate.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Transparent" 
                            TargetName="expander"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#22FFFFFF" 
                            TargetName="expander"></Setter>
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.Tag>
            <CollectionViewSource x:Name="viewSource" Source="{Binding Metrics.Modules}" behaviors:ViewSourceGroupBehavior.GroupName="MetricsModule" >
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription PropertyName="Name"/>
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>
        </Grid.Tag>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <ContentPresenter ContentTemplate="{StaticResource ModuleHeaderElement}" Content=""></ContentPresenter>
        <ScrollViewer HorizontalScrollBarVisibility="Visible" Grid.Row="1" PanningMode="Both">
            <StackPanel>
                <ItemsControl ItemsSource="{Binding Path=., ElementName=viewSource}" ItemTemplate="{StaticResource ModuleTemplate}" AlternationCount="2">
                    <ItemsControl.Template>
                        <ControlTemplate>
                            <ItemsPresenter Grid.Row="1"></ItemsPresenter>
                        </ControlTemplate>
                    </ItemsControl.Template>
                </ItemsControl>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
